<?php

class HTML_Fieldset extends HTML implements HTMLElements {
	private $attributeLegend;
	
	const HTML_FIELDSET = 'fieldset';
	const ATTRIBUTE_LEGEND = 'legend';
	
	/**
	 * 
	 * This function creates a complete Link-Element.
	 * The attributes have to be passed within an array. Possible attributes are:
	 * 	- $class
	 * 	- $id
	 * 	- $title
	 *  - $legend
	 * @param unknown_type $parent
	 * @param String[][] $properties
	 */
	public function __construct($parent, $properties)  {
		PropertySetter::setProperties($this, $properties);
		$parent->addChildElement($this);
	}
	
	public function setAttributeLegend ($legend)  {
		$this->attributeLegend = $legend;
	}
	
	public function getAttributeLegend ()  {
		return $this->attributeLegend;
	}
	
	public function getFieldsetAttributes ()  {
		
		$output = '';
		
		if (!empty($this->attributeLegend))  {
			$output .= '<'. self::ATTRIBUTE_LEGEND. '>'. $this->getAttributeLegend(). '</'. self::ATTRIBUTE_LEGEND. '>';
		}
		
		return $output;
	}
	
	public static function getAttributes ()  {
		$attributes = array();
		$parentAttributes = parent::getAttributes();
		$attributes[] = self::ATTRIBUTE_LEGEND;
		return array_merge($parentAttributes, $attributes);
	}
	
	public function toString ()  {
		$output = 	'<'. self::HTML_FIELDSET.
					$this->getHTMLAttributes(). '>'.
					$this->getFieldsetAttributes();
		
		if ($this->getChildElements())  {
			foreach ($this->getChildElements() as $element)  {
				$output .= $element->toString();
			}
		}
		
		$output .= '</'. self::HTML_FIELDSET. '>';
		
		return $output;
	}
	
}
?>